package com.woniuxy.service.impl;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.dao.WorkingDao;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.Working;
import com.woniuxy.service.WorkingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class WorkingServiceImpl implements WorkingService {
   @Autowired
    WorkingDao workingDao;

    @Override
    public void addWorking(Working working) {
   workingDao.insertWorking(working);
     log.info("添加成功");

    }

    @Override
    public void upWorking(Working working) {

   workingDao.updateWorking(working);

    }

    @Override
    public PageBean<Working> getAllWorking(Working working, int pageIndex, int pageSize) {
   try {
       PageBean<Working>pageBean=new PageBean<>();
pageBean.setPageIndex(pageIndex);
pageBean.setPageSize(pageSize);
       int count = workingDao.selectWorkingCount(working);
       pageBean.setTotalRecord(count);
pageBean.setBeanList(workingDao.selectAllWorking(working, pageIndex,pageSize));
       return pageBean;
   }catch(PersistenceException e){

       throw  new serviceException("系统维护中");
   }






    }
}
